#include "lps22hh.h"
#include "main.h"
#include "stdio.h"

uint8_t WhoAmI = 0x0f;
uint16_t DevAddress = 0xBB;
uint8_t id = 0x0;


uint8_t TEMP_OUT_L = 0x2B;
uint8_t TEMP_OUT_H = 0x2C;

void Lps22hh_read_id(void)
{
    HAL_I2C_Mem_Read(&hi2c4, DevAddress, WhoAmI, 1, &id, 1, 1000);
    printf("LPS22HH_ID --- %#x \r\n", id);    
}

uint16_t Lps22hh_read_temperature(void)
{
    uint16_t temperature = 0;
        id = 1;
        HAL_I2C_Mem_Write(&hi2c4, DevAddress, 0x11, 1, &id, 1, 1000);

        HAL_I2C_Mem_Read(&hi2c4, DevAddress, TEMP_OUT_H, 1, &id, 1, 1000);
        temperature = id << 8;
        HAL_I2C_Mem_Read(&hi2c4, DevAddress, TEMP_OUT_L, 1, &id, 1, 1000);
        temperature += id; 
    return temperature;
}

uint32_t Lps22hh_read_pressure(void)
{
        uint32_t  buff;
        uint8_t reg[3];

        HAL_I2C_Mem_Read(&hi2c4, DevAddress, 0x28, 1, &reg[0], 1, 1000);
        HAL_I2C_Mem_Read(&hi2c4, DevAddress, 0x29, 1, &reg[1], 1, 1000);
        HAL_I2C_Mem_Read(&hi2c4, DevAddress, 0x2A, 1, &reg[2], 1, 1000);
        buff = reg[2];
        buff = (buff * 256) + reg[1];
        buff = (buff * 256) + reg[0];
        buff *= 256;
    return buff;
}
    
    



